package com.android.bonn.fast.keyborad;

import android.view.MotionEvent;
import android.view.View;

public abstract class ThrottleTouchListener implements View.OnTouchListener {

    private long mLastTouchTime = 0L;

    private final static long TOUCH_SKIP_DURATION = 300L;

    @Override
    public boolean onTouch(View v, MotionEvent event) {

        long currentTime = System.currentTimeMillis();

        long touchTimeInterval = currentTime - mLastTouchTime;

        if (event.getAction() == MotionEvent.ACTION_UP && touchTimeInterval > TOUCH_SKIP_DURATION) {
            v.performClick();
            onThrottleTouch(v);
            mLastTouchTime = currentTime;
        }

        return false;
    }

    /**
     * 过滤了快速点击的方法回调
     */
    public abstract void onThrottleTouch(View v);
}